/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.ConnectUnit;
import DTO.Parameter_DTO;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author Nguyen Phi Hung
 */
public class Parameter_BLL {
    
    ConnectUnit connection;
    
    public Parameter_BLL(){
        this.connection = DAL.DAL.getDAL();
    }
    
    /**
     * get list of Parameter form database with Condition and OrderBy
     * @param condition
     * @param OrderBy
     * @return
     * @throws Exception 
     */
    public HashSet<Parameter_DTO> getParameters(String condition, String OrderBy) throws Exception{
        ResultSet result = this.connection.Select("PARAMETER", condition, OrderBy);
        HashSet<Parameter_DTO> params = new HashSet<Parameter_DTO>();
        while(result.next()){
            Parameter_DTO param = new Parameter_DTO();
            param.setInterestFreePeriod(result.getInt("InterestFreePeriod"));
            param.setMinOfDepositPeriod(result.getInt("MinOfDepositPeriod"));
            param.setMinOfWithdraw(result.getInt("MinOfWithdraw"));
            param.setMinofDeposit(result.getInt("MinofDeposit"));
            param.setFirstMinOfDeposit(result.getFloat("FirstMinOfDeposit"));
            params.add(param);
        }
        return params;
    }
    
    /**
     * get list of Parameter form database with Condition
     * @param condition
     * @return
     * @throws Exception 
     */
    public HashSet<Parameter_DTO> getParameters(String condition) throws Exception{
        return this.getParameters(condition, null);
    }
    
    /**
     * get list of Parameter form database
     * @return
     * @throws Exception 
     */
    public HashSet<Parameter_DTO> getParameters() throws Exception{
        return this.getParameters(null, null);
    }
    
    /**
     * Update Parameter into database
     * @param info
     * @throws Exception 
     */
    public void Update(Parameter_DTO info) throws Exception{
        HashMap<String,Object> map = new HashMap<String, Object>();
        map.put("InterestFreePeriod", info.getInterestFreePeriod());
        map.put("MinOfDepositPeriod", info.getMinOfDepositPeriod());
        map.put("MinOfWithdraw", info.getMinOfWithdraw());
        map.put("MinofDeposit", info.getMinofDeposit());
        map.put("FirstMinOfDeposit", info.getFirstMinOfDeposit());
        
        this.connection.Update("PARAMETER", map, null);
    }
}
